package com.contextor.magiccards.web.test;

import com.contextor.magiccards.game.auth.GameAuthenticationManager;
import com.contextor.magiccards.web.amf.AmfBattleService;
import com.contextor.magiccards.web.amf.AmfCharacterService;
import com.contextor.magiccards.web.to.Response;
import com.contextor.magiccards.web.to.battle.BattleListTO;
import com.contextor.magiccards.web.to.battle.BattleTO;
import com.contextor.magiccards.web.to.user.PersonageTO;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

/**
 * User: sergey
 * Date: Mar 22, 2011 11:51:17 AM
 */
public class AmfBattleServiceTestCase extends BaseAmfTestCase {
    @Autowired
    protected AmfBattleService battleService;
    @Autowired
    protected GameAuthenticationManager authenticationService;
    @Autowired
    protected AmfCharacterService characterService;

    final String uid = "aj4j3h5jk3k453";

    @Test
    @Ignore
    public void testCreateBattle() throws Exception {
        logger.debug("testCreateBattle");
        authenticationService.registerUser(uid);
        final Response<BattleTO> response = battleService.createBattle(uid);
        Assert.notNull(response.result);
    }

    @Test
    public void testJoinBattle() throws Exception {
        logger.debug("testJoinBattle");
        authenticationService.registerUser(uid);
        final Response<BattleTO> battleResponse = battleService.createBattle(uid);
        final BattleTO battleTO = (BattleTO) battleResponse.result;
        final Response<BattleListTO> listResponse = battleService.listBattles(uid);
        final BattleListTO listTO = (BattleListTO) listResponse.result;
        for (BattleTO item : listTO.list) {
            Assert.isTrue(item.id.equals(battleTO.id));
            Assert.isTrue(item.userId.equals(battleTO.userId));

            final Response<PersonageTO> response = characterService.loafCharacter(uid);
            PersonageTO personageTO = (PersonageTO) response.result;
            battleService.joinBattle(uid, personageTO, battleTO);
        }


    }
}
